﻿using LayoutHelpers.Primitives;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Input;
using Windows.UI.Xaml.Data;

namespace LayoutHelpers.BaseTypes
{
  public class UpdatePropertyRuleBase<T> : TypedConditionalLayoutRuleBase<T, UpdateResourcePropertyCommand>
    where T : ILayoutEvaluator, new()
  {
    virtual public string Name
    {
      get { return TypedTrueCommand.Name; }
      set { TypedTrueCommand.Name = value; if (TypedFalseCommand != null) TypedFalseCommand.Name = value; }
    }

    virtual public string Property
    {
      get { return TypedTrueCommand.Property; }
      set { TypedTrueCommand.Property = value; if (TypedFalseCommand != null) TypedFalseCommand.Property = value; }
    }

    virtual public object Value
    {
      get { return TypedTrueCommand.Value; }
      set { TypedTrueCommand.Value = value; }
    }

    virtual public object ValueIfFalse
    {
      get { return TypedFalseCommand.Value; }
      set
      {
        if (TypedFalseCommand == null)
        {
          TypedFalseCommand = new UpdateResourcePropertyCommand
          {
            Name = TypedTrueCommand.Name,
            Property = TypedTrueCommand.Property,
            ValueConverter = TypedTrueCommand.ValueConverter,
            ValueConverterParameter = TypedTrueCommand.ValueConverterParameter
          };
        }
        TypedFalseCommand.Value = value;
      }
    }

    virtual public IValueConverter ValueConverter
    {
      get { return TypedTrueCommand.ValueConverter; }
      set { TypedTrueCommand.ValueConverter = value; if (TypedFalseCommand != null) TypedFalseCommand.ValueConverter = value; }
    }

    virtual public object ValueConverterParameter
    {
      get { return TypedTrueCommand.ValueConverterParameter; }
      set { TypedTrueCommand.ValueConverterParameter = value; if (TypedFalseCommand != null) TypedFalseCommand.ValueConverterParameter = value; }
    }
  }
}
